package cn.star.jots.comments.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.comments.pojo.dto.CommentsQuery;
import cn.star.jots.comments.pojo.dto.CommentsSaveParam;
import cn.star.jots.comments.pojo.vo.CommentsVO;
import cn.star.jots.comments.service.CommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/comments")
@Slf4j
@Api(tags = "评论管理")
public class CommentsController {

    @Autowired
    CommentsService commentsService;

    @GetMapping("/search")
    @ApiOperation(value = "查询评论")
    public JsonResult search(CommentsQuery commentsQuery){
        log.info("查询评论:commentsQuery={}", commentsQuery);
        List<CommentsVO> list = commentsService.search(commentsQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/addComments")
    @ApiOperation(value = "添加评论")
    public JsonResult addComments(CommentsSaveParam commentsSaveParam){
        log.info("添加根评论:commentsSaveParam={}", commentsSaveParam);
        commentsService.addComments(commentsSaveParam);
        return JsonResult.ok();
    }

    @PutMapping("/delete/{id}")
    @ApiOperation(value = "删除评论")
    public JsonResult delete(@PathVariable Long id){
        log.info("删除评论:id={}", id);
        commentsService.delete(id);
        return JsonResult.ok();
    }

    @GetMapping("/searchAll")
    @ApiOperation(value = "查询所有评论")
    public JsonResult searchAll(CommentsQuery commentsQuery){
        log.info("查询所有评论:commentsQuery={}", commentsQuery);
        List<CommentsVO> list = commentsService.searchAll(commentsQuery);
        return JsonResult.ok(list);
    }

}
